#include "utils.h"
#include <QImage>
#include <opencv2/core.hpp>
/*
   用delim指定的正则表达式将字符串in分割，返回分割后的字符串数组
   delim 分割字符串的正则表达式
 */
std::vector<std::string> s_split(const std::string& in, const std::string& delim) {
    std::regex re{ delim };
    // 调用 std::vector::vector (InputIterator first, InputIterator last,const allocator_type& alloc = allocator_type())
    // 构造函数,完成字符串分割
    return std::vector<std::string> {
        std::sregex_token_iterator(in.begin(), in.end(), re, -1),
        std::sregex_token_iterator()
    };
}

std::shared_ptr<QImage> cvtMatToQImage(const cv::Mat& image)
{
    if(image.empty()){
        throw "no image";
    }
    QImage::Format  FORMAT;
    if(image.channels() == 1)
        FORMAT = QImage::Format_Grayscale8;
    else if(image.channels() == 3)
        FORMAT = QImage::Format_RGB888;

    std::shared_ptr<QImage> pQImg(new QImage(static_cast<const unsigned char*>(image.data), image.cols, image.rows, image.step, FORMAT));
    return pQImg;
}
